<!--  -->
<template>
    <div>

<!--内容-->
<div class="m-container ">
    <div class="ui container m-pad-tb-big m-margin-tb-big m-opacity segment" style="height:567px;">
        <div class="ui segment form">
            <div class="inline fields m-pad-tb">
                <div class="field ">
                    <input type="text" placeholder="标题" v-model="keyword">
                </div>
                <div class="field">
                    <button class="ui teal basic button" @click="getAnimes(1)"><i class="search icon"></i>搜索</button>
                </div>
            </div>
        </div>
        <table class="ui celled striped table">
            <thead>
                <tr>
                    <th></th>
                    <th>名称</th>
                    <th>开播时间</th>
                    <th>观看时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(anime,i) in pageInfo.list" :key="anime.id">
                    <td>{{i+1}}</td>
                    <td>{{anime.name}}</td>
                    <td>{{anime.createTime | formatDate("YYYY-MM-DD HH:mm")}}</td>
                    <td>{{anime.watchTime | formatDate("YYYY-MM-DD HH:mm")}}</td>
                    <td>
                        <router-link class="ui mini teal basic button" :to="'/admin/inputAnime/'+anime.id">编辑</router-link>
                        <a class="ui mini red basic button" @click="deleteAnime(anime.id)">删除</a>
                    </td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <th colspan="7">
                        <div class="ui pagination menu">
                            <a class="item" v-if="!pageInfo.isFirstPage" @click="getAnimes(pageInfo.pageNum-1)">上一页</a>
                            <a class="item" v-if="!pageInfo.isLastPage" @click="getAnimes(pageInfo.pageNum+1)">下一页</a>
                        </div>
                        <router-link class="ui  teal basic button right floated" to="/admin/inputAnime/-1"><i class="ui edit icon"></i>新增</router-link>
                    </th>
                </tr>
            </tfoot>
        </table>

    </div>
</div>

<br>
<br>
<br>

    </div>
</template>

<script>
export default {
    data () {
        return {
            keyword:"",
            pageInfo:""
        };
    },
    methods:{
        getAnimes(pageNum){
            var _this = this
            _this.axios.get("/admin/getAnimeByKeyword",{
                params:{
                    keyword:_this.keyword,
                    pageNum:pageNum
                }
            }).then(res =>{
                _this.pageInfo = res.data.pageInfo
            }).catch(e=>{
                console.log(e)
            })
        },
        deleteAnime(id){
            if(confirm('确定要删除该部番吗？')){
                var _this = this
                _this.axios.get("/admin/deleteAnime",{
                    params:{
                        id:id
                    }
                }).then(res =>{
                    if(res.data.status === 200){
                        //是否为该页最后一个
                        if(_this.pageInfo.total%5==1)
                            _this.pageInfo.pageNum-=1
                        _this.getAnimes(_this.pageInfo.pageNum)
                    }
                    alert(res.data.msg)
                }).catch(e =>{
                    console.log(e)
                })
            }
        }
    },
    created(){
        this.getAnimes()
    }
}

</script>
<style lang='scss' scoped>
</style>